home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / hobbspr2 / etc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-24  |  3.4 KB  |  156 lines

  1. // Mode X Sprite Library
  2. // Copyright (C) 1992 Court Demas  --  court+@cmu.edu
  3.  
  4. #pragma hdrfile "etc.SYM"
  5. #ifndef ETC_H
  6. #define ETC_H
  7.  
  8. #define TRUE 1
  9. #define FALSE 0
  10. typedef char BOOL;
  11.  
  12. /*
  13. A simple class for any object which has a fixed position.
  14. I am using GetX() and GetY() so that I can change the coordinate system later
  15. if I want to (maybe polar? :-)).  I might use fixed-point longs, dividing
  16. each one by 10 or 100 so I could get some accuracy when moving along
  17. diagonals.  Get*() and Set*() would then multiply or divide my that amount
  18. to get the integer value.
  19. */
  20.  
  21. class TCoordinate {
  22.  
  23.   protected:
  24.     int        x,y;
  25.  
  26.   public:
  27.     TCoordinate() {};
  28.     TCoordinate(int sx,int sy) { x=sx; y=sy; }
  29.  
  30.     int        GetX(void)                     { return x; }
  31.     int        GetY(void)                     { return y; }
  32.  
  33.     void    SetX(int newx)                 { x = newx; }
  34.     void     SetY(int newy)                { y = newy; }
  35.     void    SetXY(int newx,int newy)     { x = newx; y = newy; }
  36.     void     MoveUp(int dy=1)            { y -= dy; }
  37.     void     MoveDown(int dy=1)             { y += dy; }
  38.     void    MoveLeft(int dx=1)            { x -= dx; }
  39.     void     MoveRight(int dx=1)            { x += dx; }
  40.  
  41. };
  42.  
  43.  
  44. class TRectangle {
  45.   private:
  46.     TCoordinate        Size;
  47.  
  48.   public:
  49.     TCoordinate        Start,
  50.                     End;
  51.  
  52.  
  53.                 TRectangle() {}
  54.  
  55.     void        Set(int sx, int sy, int ex, int ey) {
  56.                     Start.SetXY(sx,sy);
  57.                     End.SetXY(ex,ey);
  58.                     Size.SetX(ex - sx);
  59.                     Size.SetY(ey - sy);
  60.                 }
  61.  
  62.     int            GetWidth(void) {
  63.                     return Size.GetX();
  64.                     }
  65.     int            GetHeight(void) {
  66.                     return Size.GetY();
  67.                     }
  68.  
  69. };
  70.  
  71.  
  72. // These are specific to how many possible directions you want and should be
  73. // put in a different header.
  74. #define UP             0
  75. #define UPRIGHT     1
  76. #define RIGHT         2
  77. #define DOWNRIGHT     3
  78. #define DOWN         4
  79. #define DOWNLEFT     5
  80. #define LEFT         6
  81. #define UPLEFT        7
  82.  
  83. class TVector {
  84.  
  85.   protected:
  86.     int        dx, dy;
  87.  
  88.   public:
  89.  
  90.             TVector(void)                { dx=0; dy=0; }
  91.  
  92.     void     SetDeltaX(int newdx)        { dx = newdx; }
  93.     void     SetDeltaY(int newdy)        { dy = newdy; }
  94.     void    SetDeltaXY(int x, int y)    { dx=x; dy=y; }
  95.     int        GetDeltaX(void)                { return dx; }
  96.     int        GetDeltaY(void)                { return dy; }
  97.  
  98. };
  99.  
  100.  
  101. /*
  102. A class for keeping track of the position and vector of an object.  I might
  103. create an separate Speed_Class, but maybe that's going a little overboard..
  104.  
  105. Assumes that you want 8 directions - just to be stupid.
  106. */
  107.  
  108. class     TPVector : public TCoordinate, public TVector {
  109.  
  110.  
  111.   private:
  112.         int     maxSpeed,
  113.                 minSpeed,
  114.                 Speed;
  115.  
  116.     void    NormSpeed(void) {
  117.                 if (Speed < minSpeed) Speed = minSpeed;
  118.                 if (Speed > maxSpeed) Speed = maxSpeed;
  119.                 }
  120.  
  121.   public:
  122.             TPVector() :     TCoordinate(),
  123.                             TVector() {}
  124.  
  125.             TPVector(int smax,int smin) :
  126.                     TCoordinate(),
  127.                     TVector()
  128.                 {
  129.                 SetDeltaX(-1);
  130.                 SetDeltaY(0);
  131. //                SetDirection(UP);
  132.                 maxSpeed    =    smax;
  133.                 minSpeed    =    smin;
  134.                 Speed         =    0;
  135.                 }
  136.  
  137.  
  138.     // Updates the coordinates of the sprite based on speed/direction.
  139.     void    Update_Position(void);
  140.  
  141.     void    SetMaxSpeed(int _max)    { maxSpeed = _max;         }
  142.     void     SetMinSpeed(int _min)    { minSpeed = _min;         }
  143.  
  144.     void    Faster(int d=1)        { Speed+=d; NormSpeed();     }
  145.     void     Slower(int d=1)        { Speed-=d; NormSpeed();     }
  146.     void    Stop(void)            { Speed = 0;                 }
  147.  
  148.     void    SetSpeed(int s)        { Speed = s;                }
  149.     int        GetSpeed(void)        { return Speed;             }
  150. };
  151.  
  152. #endif
  153. #pragma hdrstop
  154. //*****************************************************************************
  155. // End of etc.h
  156.